﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IceDog.DNL.CSharp.DesignPattern.DataAccessObjectPattern.StudentManage;

namespace IceDog.DNL.CSharp.DesignPattern.DataAccessObjectPattern.StudentManage
{
    public class StudentDao:IStudentDao
    {
        private readonly List<Student> _students;

        public StudentDao()
        {
            _students = new List<Student>
            {
                new Student("1","ford"),
                new Student("2","jame"),
                new Student("3","robert"),
            };
        }

        public List<Student> GetAllStudents()
        {
            return _students;
        }

        public Student GetStudent(string rollNo)
        {
            return _students.First(s => s.RollNo.Equals(rollNo));
        }

        public void UpdateStudent(Student student)
        {
            _students.First(s => s.RollNo.Equals(student.RollNo)).Name=student.Name;
        }

        public void DeleteStudent(Student student)
        {
            _students.Remove(_students.First(s => s.RollNo.Equals(student.RollNo)));
        }

        public void AddStudent(Student student)
        {
            _students.Add(student);
        }
    }
}
